function Storage() {
  this.clear();
  this.nextSetShouldThrow = false;
};

Storage.prototype.toString = function() {
  return '[object Storage]';
};

Storage.prototype.setLength_ = function(value) {
  Object.defineProperty(this, "length", {
    value: value,
    writable: false,
    enumerable: true,
    configurable: true
  });
};

Storage.prototype.setItem = function(key, value) {
  if (this.nextSetShouldThrow) {
    this.nextSetShouldThrow = false;
    throw('QUOTA_EXCEEDED_ERROR - Storage.setItem - this Storage has exceeded capacity');
  }
  var key = key.toString();
  if (this.backingStorage_[key] === undefined) {
    this.setLength_(this.length + 1);
  }
  this.backingStorage_[key] = value.toString();
  this.__defineGetter__(key, function(){
    return this.backingStorage_[key];
  });
  this.__defineSetter__(key, function(val){
    this.backingStorage_[key] = val.toString();
  });
};

Storage.prototype.removeItem = function(key) {
  if (this.backingStorage_.hasOwnProperty(key)) {
    this.setLength_(this.length - 1);
    delete this.backingStorage_[key];
    delete this[key];
  }
};

Storage.prototype.getItem = function(key) {
  return this.backingStorage_[key];
};

Storage.prototype.clear = function() {
  this.setLength_(0);
  for (key in this.backingStorage_) {
    delete this[key];
  }
  this.backingStorage_ = {};
};

Storage.prototype.key = function(index) {
  for (i in this.backingStorage_) {
    if (index-- == 0) {
      return i;
    }
  }
  return null;
};